<template>
    <ynet-content id="newAccount" :headerInformation="true" :headerMenu="true" class="main-container">
        <div>
			<ynet-breadcrumb></ynet-breadcrumb>
		</div>
        
        <div class="functionalArea">
            <!--<ynet-progress-bar class="mt10" :items="stepText" :itemIndex="stepIndex"></ynet-progress-bar>-->
            <fillinPage v-if="stepIndex=='0'" @changeStep="changeStep" :fillinMsg="formData"></fillinPage>
            <confirmPage v-if="stepIndex=='1'" @changeStep="changeStep" :confirmMsg="formData"></confirmPage>
            <resultPage v-if="stepIndex=='2'" @changeStep="changeStep" :resultMsg="formData"></resultPage>
        </div>
        
        <!--授权确认页面弹窗-->
        <div>
            <ynet-authDialog ref="dialogTable"  @getAuthForm="getAuthForm"></ynet-authDialog>
        </div>
    </ynet-content>
</template>

<script>
    import fillinPage from './components/newAccount_input'    //填充存入开立信息表单
    import confirmPage from './components/newAccount_confirm'    //交易确认页面
    import resultPage from './components/newAccount_result'    //交易完成页面
	export default {
		name:'newAccount',
		components:{
            fillinPage,
            confirmPage,
            resultPage
		},
		data(){
            return {
                stepIndex: 0,
                formData: {
                    acctNo: ''
                }
            }
        },
		methods:{
            changeStep(index,formData){
                let _this = this
                _this.stepIndex = index
                if(formData) _this.formData = formData
                _this.$tools.scrollTop()
            },
            handleCurrentChange(val) {//查询分页方法
                this.queryForm.currentPage=val;
                this.queryChange()
            },
           resetForm(formName){
                this.$refs[formName].resetFields();
           },
           getAuthForm(val){
                //获取授权数据
                this.authForm=val;
                console.log("val:"+JSON.stringify(val))
                this.addForm=$.extend(this.addForm,this.authForm)
                this.typhoonAdd()  //自己页面提交给后台的.do方法
            },
            tanchuang(val){
                 this.delForm=$.extend({},this.delForm,val);
                console.log("delForm:"+JSON.stringify(this.delForm))
                this.$confirm('Confirm to delete','warning',{
                    confirmButtonText:'Confirm',
                    cancelButtonText:'Cancel',
                    type:'warning'
                }).then(()=>{
                    this.queryAuth()
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'cancel',
                    })
                })
            },
           queryAuth(formName){//查询授权模式
                this.$refs[formName].validate((valid)=>{
                    if(valid){
                        let body={};body.bsnCode="IM0203";body.version="IM0203",
                        this.$tools.request(this,"IM010001Action.do",body).then(data=>{
                            if(data.body.errorCode==0){
                                if(data.body.needAuth==0){//无需授权
                                    this.typhoonAdd()
                                }else if(data.body.needAuth==1 && data.body.authType==1){
                                    this.needAuth=1;
                                    this.authType=1;
                                    this.$refs["dialogTable"].show()
                                            // this.dialogTableVisible=true;
                                }else if( data.body.needAuth==1 && data.body.authType==2 ){
                                    this.needAuth=1;
                                    this.authType=2;
                                    this.typhoonAdd()
                                }else{
                                    this.$alert('Authorization Type Error', {
                                        confirmButtonText: 'Confirm',
                                        callback: action => {
                                        }
                                    });
                                }
                            }else{
                                this.$alert("System Error Try again", "warning",{
                                    confirmButtonText: 'Confirm',
                                    callback: action => {
                                    }
                                });
                            }
                        })   
                    }
                })
                
			},
           delAccess(val){//删除
                this.$tools.request(this,"IM0203Action.do",this.delForm).then(data=>{
                    if(data.body.errorCode==0){
                        if(this.needAuth==1 && this.authType==2){
                            this.$message({
								type:'success',
								message:'Waiting for Authorized'
							})
                        } else if(this.needAuth==1 && this.authType==1){
                            if(data.body.authStatus==1){
                                this.$message({
                                    type:'warning',
                                    message:'Authorship No. or password wrong ,please resume load',
                                    showClose:true,
                                })
                                this.queryChange()
                            }else{
                                this.$message({
                                    type:'success',
                                    message:'Delete Success',
                                    showClose:true,
                                })
                                this.queryChange()
                            }
                        }else{
                            this.$message({
                                type:'success',
                                message:'Delete Success',
                                showClose:true,
                            })
                        }
                        
                    }else{
                         this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                    }
                })
           },
           systemAdd(){//点击新增按钮,显示新增页面
                this.main=false;
                this.isAdd=true;
           },
           updateSystem(val){//点击修改按钮,反显选中的数据
                console.log("updatval:"+JSON.stringify(val))
                this.editData=$.extend({},this.editData,val)
                this.main=false;
                this.isAdd=false;
                this.isEdit=true;
           },
           queryChange(){
                this.$tools.request(this,"IM0203QueryAction.do",this.queryForm).then(data=>{
                   console.log("data:"+JSON.stringify(data))
                   if(data.body.errorCode==0){
                        this.systemSetList=data.body.paramList;
                        this.turnPageTotalNum=data.body.turnPageTotalNum;
                   }else{
                       this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                   }
               })
           },
           query(val){//查询频率控制
                //console.log("val:"+JSON.stringify(val))
                this.queryForm.currentPage=1
                console.log("queryForm:"+JSON.stringify(this.queryForm))
                this.queryChange()
            },
            back(){
                this.main=true;
                this.isAdd=false;
                this.isEdit=false;
                this.queryChange();
            }
            
		}
	}
</script>